﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PowershellHost.cs" company="Collaboris Ltd.">
//   Copyright (c) Collaboris Ltd. All rights Reserved.
// </copyright>
// <summary>
//   The host class.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Collaboris.Saf.Actions.Powershell
{
    using System;
    using System.Management.Automation.Host;
    using System.Threading;

    /// <summary>
    /// The host class.
    /// </summary>
    public class PowershellHost : PSHost
    {
        public PowershellHost(IPowershellAction action)
        {
            this.action = action;

            this.ui = new PowershellHostUI(action);
        }

        public override System.Globalization.CultureInfo CurrentCulture
        {
            get { return Thread.CurrentThread.CurrentCulture; }
        }

        public override System.Globalization.CultureInfo CurrentUICulture
        {
            get { return Thread.CurrentThread.CurrentUICulture; }
        }

        public override void EnterNestedPrompt()
        {
            throw new NotImplementedException();
        }

        public override void ExitNestedPrompt()
        {
            throw new NotImplementedException();
        }

        public override Guid InstanceId
        {
            get { return instanceGuid; }
        }

        public override string Name
        {
            get { return typeof(PowershellHost).Name; }
        }

        public override void NotifyBeginApplication()
        {
            // nothing
        }

        public override void NotifyEndApplication()
        {
            // nothing
        }

        public override void SetShouldExit(int exitCode)
        {
            this.action.ShouldExit = true;
            this.action.ExitCode = exitCode;
        }

        public override PSHostUserInterface UI
        {
            get { return this.ui; }
        }

        public override Version Version
        {
            get { return new Version(1, 0, 0, 0); }
        }


        private readonly IPowershellAction action;
        private readonly PowershellHostUI ui;
        private static readonly Guid instanceGuid = Guid.NewGuid();
    }
}